Page({
  data: {
    userAddress:''
  },
  // 获取缓存中收货地址
  onShow(){
    let that = this;
    wx.getStorage({
      key: "userAddress",
      success: function(res){
        that.setData({
          userAddress:res.data
        })
      }
    })
  },
  // 删除地址
  handleDelete(e){
    let that = this;
    // console.log(e.currentTarget.dataset.id);
    let id=e.currentTarget.dataset.id;
    let userAddress=this.data.userAddress;
    // 找到要删除地址
    // 弹窗提示
    wx.showModal({
      title:'提示',
      content:'您是否要删除？',
      success:(res)=>{
        if(res.confirm){
          // 删除地址
          userAddress.splice(id,1);
          // 更改当前页面地址为删除后地址
          that.setData({
            userAddress
          })
          // 把地址添加到缓存中
          wx.setStorageSync("userAddress",userAddress);
        }else if(res.cancel){
          console.log('用户点击取消');
        }
      }
    })
    
  },
  // 跳转到添加收货地址页 并告知从哪也跳转来的
  handleAddAddress(){
    wx.navigateTo({
      url: '/pages/addAddress/addAddress?fromPage=myAddress'
    })
  },
})